package cn.xiaomubiao.oschine.fragment.Event_fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.xiaomubiao.oschine.MyApplication;
import cn.xiaomubiao.oschine.R;
import cn.xiaomubiao.oschine.base.BaseNavFragment;
import cn.xiaomubiao.oschine.bean.PostDetail;
import cn.xiaomubiao.oschine.contants.Host;
import cn.xiaomubiao.oschine.util.HttpUtil;

/**
 * Created by King Su on 2017/4/7.
 */

public class EventFragment extends BaseNavFragment {


    @BindView(R.id.tv_detail_title)
    TextView mTvDetailTitle;
    @BindView(R.id.tv_detail_time)
    TextView mTvDetailTime;
    @BindView(R.id.tv_event_address)
    TextView mTvEventAddress;
    @BindView(R.id.lv_address)
    LinearLayout mLvAddress;
    @BindView(R.id.btn_event_bm)
    Button mBtnEventBm;
    @BindView(R.id.wv_event)
    WebView mWvEvent;
    @BindView(R.id.keyboard)
    ImageView mKeyboard;
    @BindView(R.id.edt_comment)
    EditText mEdtComment;
    @BindView(R.id.iv_emoji)
    ImageView mIvEmoji;
    @BindView(R.id.iv_send_message)
    ImageView mIvSendMessage;
    Unbinder unbinder;

    @Override
    public View initView() {
        View rootView = View.inflate(mActivity, R.layout.event_detail_fragment, null);

        return rootView;
    }

    @Override
    public void initData() {
        Bundle b = getArguments();
        int id = (int) b.get("id");
        final String eventTitle = (String) b.get("eventTitle");
        final String time = (String) b.get("time");
        final String address = (String) b.get("address");
        String url = Host.HOST_DEFAULT + "detail/post_detail/" + id + ".xml";
        HttpUtil httpUtil = new HttpUtil(getContext(), PostDetail.class);
        httpUtil.getStringData(url, new HttpUtil.OnGetDataListener<PostDetail>() {
            @Override
            public void onSuccess(PostDetail o) {
                final String body = o.getPost().getBody();
                MyApplication.mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mTvDetailTitle.setText(eventTitle);
                        mTvDetailTime.setText(time);
                        mTvEventAddress.setText(address);
                        mWvEvent.loadDataWithBaseURL(null, body, "text/html", "utf-8", null);
                    }
                });

            }

            @Override
            public void onFailure(Exception e) {

            }
        });

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @OnClick({R.id.lv_address, R.id.btn_event_bm, R.id.keyboard})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.lv_address:
                break;
            case R.id.btn_event_bm:
                break;
            case R.id.keyboard:
                break;
        }
    }
}
